<?php
/**
 * Create a dir follow current date
 * @param : 1-only create year
 *          2-create year/month
 *          3-create year/month/day
 */
function createDateDir($dir = 'uploads', $option = 3) {
    $folder = getcwd();
    $year   = date('Y');
    $month  = date('m');
    $day   = date('d');
    
    //Create folder
    $yDir = $folder.'/uploads/'.$year;
    if (!is_dir($yDir)) {
        mkdir($yDir, 0777);
    } 
    
    if ($option == 1) {
        return;
    }
    
    $mDir = $folder.'/uploads/'.$year.'/'.$month;
    if (!is_dir($mDir)) {
        mkdir($mDir, 0777);
    }
    
    if ($option == 2) {
        return;
    }
    
    $dDir = $folder.'/uploads/'.$year.'/'.$month.'/'.$day;   
    if(!is_dir($dDir)) {
       mkdir($dDir, 0777); 
    }
}
createDateDir('uploads', 3);
?>
